
Imports System.Data
Imports System.Data.SqlClient
Partial Class Admin_frmTabSubCategory
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _SubCategoryVO As New SubCategoryVo()
    Dim _EmployeeId As String
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _SubCategoryVO.CategoryId = ddlCategoryId.SelectedValue.ToString
            _SubCategoryVO.SubCategoryId = txtSubCategoryId.Text
            _SubCategoryVO.SubCategoryName = txtSubCategoryName.Text
            _BO.InsertSubCategory(_SubCategoryVO)
            ClearAll()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        ddlCategoryId.SelectedIndex = 0
        txtSubCategoryId.Text = ""
        txtSubCategoryName.Text = ""
        MsgBox("SubCategory inserted")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        If Not IsPostBack Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
            CategoryData()
        End If
     
    End Sub
    Public Sub CategoryData()
        Dim dtCategory As DataTable
        dtCategory = _BO.getcategory()
        ddlCategoryId.DataSource = dtCategory
        ddlCategoryId.DataValueField = dtCategory.Columns(0).ToString
        ddlCategoryId.DataTextField = dtCategory.Columns(1).ToString
        ddlCategoryId.DataBind()
    End Sub
    'Protected Sub gdSubCategory_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdSubCategory.DeleteCommand
    '    _BO.DeleteSubCategory(e.Item.Cells(0).Text)
    'End Sub
    Sub GridData()
        Dim dtSubCategory As DataTable
        dtSubCategory = _BO.getSubCategoryDetails()
        gdSubCategory.DataSource = dtSubCategory
        gdSubCategory.DataBind()
    End Sub
    Protected Sub gdSubCategory_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdSubCategory.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifySubCategory.aspx?SubCategoryId=" & e.Item.Cells(1).Text)
    End Sub
    Protected Sub gdSubCategory_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdSubCategory.DeleteCommand
        _BO.DeleteSubCategory(e.Item.Cells(1).Text)
        Response.Redirect("frmTabSubCategory.aspx")
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub
    Protected Sub gdSubCategory_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdSubCategory.PageIndexChanged
        gdSubCategory.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtSubCategoryId.Text = ""
        txtSubCategoryName.Text = ""
    End Sub
End Class
